import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";

export default new Vuex.Store({
  state: {
    list: [
      { title: "任务一", status: true },
      { title: "任务2", status: false },
    ],
  },
  mutations: {
    add(state, title) {
      state.list.push({ title: title, status: false });
    },
    change(state, i) {
      state.list[i].status = !state.list[i].status;
    },
  },
  actions: {},
  modules: {},
  getters: {
    num(state) {
      let num1 = state.list.filter((item) => {
        return item.status == true;
      }).length;

      return { num1: num1, num2: state.list.length - num1 };
    },
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
  //插件 配置持久化插件
});
